clear all
set more off
global path "C:\Users\micha\Dropbox\Pills JFQA\Replication Package JFQA\"

//##############################################
//Announcement Returns
cd "$path\Created Datasets"
use PPL_toanalyze, clear


//MN 1994 - presented to governor 5/4/1995; signed by governor 5/5/1995
//SC 1997 - approved by goverrnor 6/8/1998 
//WA 1997 - passed House 2/9/1998, passed Senate 3/5/1998; approved by governor 3/23/1998
//MD 1998 - approved 5/13/1999
//MO 1998 - approved 7/13/1999
//MI 2000 - approved by the governor, 7/23/2001
//ME 2001 - effective 7/1/2001 (imputed approval date is 90 days before, so 4/2/2001, a Monday)
//CT 2002 - approved 6/26/2003
//TX 2002 - approved 5/29/2003
//MS 2004 - approved 4/20/2005
//VT 2007 - approved 6/5/2008
//WY 2008 - approved 3/3/2009

//Lists of PERMNOs as of 1994/1/3, 1997/1/2, 1998, 2000, 2001, 2002, 2004, 2007, 2008

//##############################################
// 1994 List
//##############################################
cd "$path\TableOA10"
//1994 Permno list as of 01/03/1994 (Monday)
use permno_1994_rsxwrqhthb9zwt0m, replace
rename *,lower
order *, sequential
format date %tdCCYYNNDD
keep permno date siccd
save permno_1994, replace

export excel event_1994, replace
//Goes to WRDS Event Study file for MM returns

//##############################################
// 1997 List
//##############################################
cd "$path\TableOA10"
//1997 Permno list as of 01/03/1997 (Friday)
use permno_1997_c88whdmxqmbvkwze, replace
rename *,lower
order *, sequential
format date %tdCCYYNNDD
keep permno date siccd
save permno_1997, replace

export excel event_1997, replace
//Goes to WRDS Event Study file for MM returns

//##############################################
// 1998 List
//##############################################
cd "$path\TableOA10"
//1998 Permno list as of 01/02/1998 (Friday)
use permno_1998_o1cw1u0izvlfk1v8, replace
rename *,lower
order *, sequential
format date %tdCCYYNNDD
keep permno date siccd
save permno_1998, replace

export excel event_1998, replace
//Goes to WRDS Event Study file for MM returns

//##############################################
// 2000 List
//##############################################
cd "$path\TableOA10"
//2000 Permno list as of 01/03/2000 (Monday)
use permno_2000_fh7bboss5a0uaepz, replace
rename *,lower
order *, sequential
format date %tdCCYYNNDD
keep permno date siccd
save permno_2000, replace

export excel event_2000, replace
//Goes to WRDS Event Study file for MM returns


//##############################################
// 2001 List
//##############################################
cd "$path\TableOA10"
//2001 Permno list as of 01/03/2001 (Wednesday)
use permno_2001_lajxd8sk5roji4zz, replace
rename *,lower
order *, sequential
format date %tdCCYYNNDD
keep permno date siccd
save permno_2001, replace

export excel event_2001, replace
//Goes to WRDS Event Study file for MM returns


//##############################################
// 2002 List
//##############################################
cd "$path\TableOA10"
//2002 Permno list as of 01/03/2002 (Thursday)
use permno_2002_ihpvctrnmrglrkzq, replace
rename *,lower
order *, sequential
format date %tdCCYYNNDD
keep permno date siccd
save permno_2002, replace

export excel event_2002, replace
//Goes to WRDS Event Study file for MM returns


//##############################################
// 2004 List
//##############################################
cd "$path\TableOA10"
//2004 Permno list as of 01/02/2004 (Friday)
use permno_2004_gmx6j9nsirtyt7oe, replace
rename *,lower
order *, sequential
format date %tdCCYYNNDD
keep permno date siccd
save permno_2004, replace

export excel event_2004, replace
//Goes to WRDS Event Study file for MM returns


//##############################################
// 2007 List
//##############################################
cd "$path\TableOA10"
//2007 Permno list as of 01/03/2007 (Wednesday)
use permno_2007_yjt0fjal4k2v81fz, replace
rename *,lower
order *, sequential
format date %tdCCYYNNDD
keep permno date siccd
save permno_2007, replace

export excel event_2007, replace
//Goes to WRDS Event Study file for MM returns


//##############################################
// 2008 List
//##############################################
cd "$path\TableOA10"
//2008 Permno list as of 01/03/2008 (Thursday)
use permno_2008_waaspswm3lwgc3u3, replace
rename *,lower
order *, sequential
format date %tdCCYYNNDD
keep permno date siccd
save permno_2008, replace

export excel event_2008, replace
//Goes to WRDS Event Study file for MM returns




//##############################################
// CAR Returns
//##############################################
cd "$path\TableOA10"
import sas event_1994_qdcx0vn9azi3qcmb0, clear 
rename *, lower
order *, sequential
g incs="MN"
keep car_window_1 car_window_2 car_window_3 car_window_4 car_window_5 car_window_6 eventdat permno name incs
format eventdat %tdCCYYNNDD
joinby permno using permno_1994, unmatched(master)
save eventus_1994, replace

//##############################################
import sas event_1997_SC_qpbl9vhskbvsl0hor, clear 
rename *, lower
order *, sequential
g incs="SC"
keep car_window_1 car_window_2 car_window_3 car_window_4 car_window_5 car_window_6 eventdat permno name incs
format eventdat %tdCCYYNNDD
joinby permno using permno_1997, unmatched(master)
save eventus_1997_SC, replace

//##############################################
import sas event_1997_WA_qifuxjr3fsdcl0nuo, clear 
rename *, lower
order *, sequential
g incs="WA"
keep car_window_1 car_window_2 car_window_3 car_window_4 car_window_5 car_window_6 eventdat permno name incs
format eventdat %tdCCYYNNDD
joinby permno using permno_1997, unmatched(master)
save eventus_1997_WA, replace

//##############################################
import sas event_1998_MD_qjryau3ok2ibx8xra, clear 
rename *, lower
order *, sequential
g incs="MD"
keep car_window_1 car_window_2 car_window_3 car_window_4 car_window_5 car_window_6 eventdat permno name incs
format eventdat %tdCCYYNNDD
joinby permno using permno_1998, unmatched(master)
save eventus_1998_MD, replace

//##############################################
import sas event_1998_MO_qyszcdll2aiaav99d, clear 
rename *, lower
order *, sequential
g incs="MO"
keep car_window_1 car_window_2 car_window_3 car_window_4 car_window_5 car_window_6 eventdat permno name incs
format eventdat %tdCCYYNNDD
joinby permno using permno_1998, unmatched(master)
save eventus_1998_MO, replace

//##############################################
import sas event_2000_qyh5z920dvxvi7qgz, clear 
rename *, lower
order *, sequential
g incs="MI"
keep car_window_1 car_window_2 car_window_3 car_window_4 car_window_5 car_window_6 eventdat permno name incs
format eventdat %tdCCYYNNDD
joinby permno using permno_2000, unmatched(master)
save eventus_2000, replace

//##############################################
import sas event_2001_qhx8h8evevupvmuhh, clear 
rename *, lower
order *, sequential
g incs="ME"
keep car_window_1 car_window_2 car_window_3 car_window_4 car_window_5 car_window_6 eventdat permno name incs
format eventdat %tdCCYYNNDD
joinby permno using permno_2001, unmatched(master)
save eventus_2001, replace

//##############################################
import sas event_2002_CT_qyvdgwvbgfyocdmq9, clear 
rename *, lower
order *, sequential
g incs="CT"
keep car_window_1 car_window_2 car_window_3 car_window_4 car_window_5 car_window_6 eventdat permno name incs
format eventdat %tdCCYYNNDD
joinby permno using permno_2002, unmatched(master)
save eventus_2002_CT, replace

//##############################################
import sas event_2002_TX_qtixz6enztslhwyjl, clear 
rename *, lower
order *, sequential
g incs="TX"
keep car_window_1 car_window_2 car_window_3 car_window_4 car_window_5 car_window_6 eventdat permno name incs
format eventdat %tdCCYYNNDD
joinby permno using permno_2002, unmatched(master)
save eventus_2002_TX, replace

//##############################################
import sas event_2004_qj81nmurhvhqhq22v, clear 
rename *, lower
order *, sequential
g incs="MS"
keep car_window_1 car_window_2 car_window_3 car_window_4 car_window_5 car_window_6 eventdat permno name incs
format eventdat %tdCCYYNNDD
joinby permno using permno_2004, unmatched(master)
save eventus_2004, replace

//##############################################
import sas event_2007_qtejjsoe30fgqmfcz, clear 
rename *, lower
order *, sequential
g incs="VT"
keep car_window_1 car_window_2 car_window_3 car_window_4 car_window_5 car_window_6 eventdat permno name incs
format eventdat %tdCCYYNNDD
joinby permno using permno_2007, unmatched(master)
save eventus_2007, replace

//##############################################
import sas event_2008_qaxyswlmgltwgnhv4, clear 
rename *, lower
order *, sequential
g incs="WY"
keep car_window_1 car_window_2 car_window_3 car_window_4 car_window_5 car_window_6 eventdat permno name incs
format eventdat %tdCCYYNNDD
joinby permno using permno_2008, unmatched(master)
save eventus_2008, replace
//##############################################

//##############################################
//Combine CARs
//##############################################
use eventus_1994, clear
append using eventus_1997_SC, force
append using eventus_1997_WA, force
append using eventus_1998_MD, force
append using eventus_1998_MO, force
append using eventus_2000, force
append using eventus_2001, force
append using eventus_2002_CT, force
append using eventus_2002_TX, force
append using eventus_2004, force
append using eventus_2007, force
append using eventus_2008, force
save CARs, replace

//##############################################
cd "$path\Created Datasets"
use PPL_toanalyze, clear
cd "$path\TableOA10"

//Keep the first year of implementing PPL
sort gvkey fyear, stable
keep if pplh1==1 
by gvkey: gen num=_n
keep if num==1
drop num
drop if fyear<=1993
drop if fyear>=2010

g permno=lpermno
replace permno=npermno if lpermno==.&npermno!=.

keep permno incs conm company_name pplh1
save firstyearppl, replace

//##############################################
use CARS, clear
drop _merge
joinby permno incs using firstyearppl, unmatched(master)
replace pplh1=0 if pplh1==.
g year=year(eventdat)

g sic2=round(siccd/100-.5,1)
g sic3=round(siccd/10-.5,1)

winsor2 car_window_1 car_window_2 car_window_3 car_window_4 car_window_5 car_window_6, cuts(1 99)

eststo clear
eststo: reghdfe car_window_1_w pplh1, absorb(sic3 ) 
eststo: reghdfe car_window_2_w pplh1, absorb(sic3 ) 
eststo: reghdfe car_window_3_w pplh1, absorb(sic3 ) 
eststo: reghdfe car_window_4_w pplh1, absorb(sic3 ) 
eststo: reghdfe car_window_5_w pplh1, absorb(sic3 ) 
eststo: reghdfe car_window_6_w pplh1, absorb(sic3 ) 

esttab using "$path/Results/Tab_OA10.csv", keep(pplh*) replace stats(N r2_a) star(+ 0.15 * 0.1 ** 0.05 *** 0.01)